/**
 * Copyright 2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * ChunMap是开源软件。你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。
 * 
 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 * 
 * 下面此段程序作者YangJianDong(chunquedong)
 * 最后修改时间2010.7.17
 */
package chunmap.model.crs;

import java.util.ArrayList;
import java.util.List;

import chunmap.data.provider.LayerFactory;
import chunmap.model.coord.Coordinate2D;
import chunmap.model.coord.Position;
import chunmap.model.geom.Geometry;
import chunmap.model.geom.LineString;
import chunmap.view.layer.VectorLayer;

public class BLGrid {
	public VectorLayer createGrid()
    {
        List<Geometry> geometrys = new ArrayList<Geometry>();
        addGeometry(geometrys);

        VectorLayer layer = LayerFactory.createGeometryLayer(geometrys);
        return layer;
    }
    private void addGeometry(List<Geometry> geometrys)
    {
        //-180<x>180
        //-90<y>90
        for (int i = -90; i <= 90; i += 10)
        {
            addWeiXian(geometrys, i);
        }
        for (int i = -180; i <= 180; i += 10)
        {
            addJingXian(geometrys, i);
        }
    }

    private void addWeiXian(List<Geometry> geometrys, double weidu)
    {
        LineString ls = new LineString(
            new Position[] { new Coordinate2D(-180, weidu), new Coordinate2D(180, weidu) });
        geometrys.add(ls);
    }

    private void addJingXian(List<Geometry> geometrys, double jingdu)
    {
        LineString ls = new LineString(
            new Position[] { new Coordinate2D(jingdu, -90), new Coordinate2D(jingdu, 90) });
        geometrys.add(ls);
    }
}
